<?php
require_once('model/Db.php');
require_once('model/Mail.php');
$Db = Db::getInstance();
$Mail = Mail::getInstance();
if(isset($_POST['submit'])){
	//转义
	$_POST = $Db->escape($_POST);
	//token = 时间戳+6位随机数
	$token = time().substr(str_shuffle('0123456789'),0,6);
	$save_flag = $Db->save([
		table => 'tmp_user',
		map => [
			user => $_POST['user'],
			nick => $_POST['nick'],
			pwd => sha1(md5($_POST['pwd'])),
			email => $_POST['email'],
			sex => $_POST['sex'],
			phone => $_POST['phone'],
			active_time => '#DATE_ADD(NOW(),INTERVAL 1 DAY)#',
			token => $token
		]
	]);
	if($save_flag){
		$mail_flag = $Mail->send([
			toemail => $_POST['email'],
			toname => $_POST['user'],
			subject => '青柠账号激活',
			body => "<h3>嗨~欢迎使用青柠BBS！</h3><a href='https://syxingchuang.com/nsbbs/active.php?token={$token}'>点击此链接激活您的青柠账号:{$_POST['user']} ({$_POST['nick']})</a>"
		]);
		if(!$mail_flag){
			$err = '<div class="err-net"><span>网络波动较大,请稍后再试</span></div>';
		}
	}
       
}

$Db->close();
include './view/register.all.html';